package com.five.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.five.dao.ClubDao;
import com.five.pojo.Club;
import com.five.pojo.ClubJoin;
import com.five.pojo.PageBean;
import com.five.service.ClubService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author lenovo
 */
@Service
public class ClubServiceImpl implements ClubService {

    @Autowired
    ClubDao clubDao;
    @Override
    public List<Club> getAll() {
        QueryWrapper<Club> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("*");
        List<Club> list = clubDao.selectList(queryWrapper);
        return list;
    }

 //分页
    @Override
    public PageBean page(Integer page, Integer pageSize , String cName , String cType){
        //1.设置分页参数
        PageHelper.startPage(page , pageSize);
        //2.执行查询
        List<Club> clubList = clubDao.list2(cName , cType);
        Page<Club> p = (Page<Club>) clubList;
        //3.封装PageBean对象
        PageBean pageBean = new PageBean(p.getTotal() , p.getResult());
        return pageBean;
    }

    //新社团入驻娱乐天地(团长 =》管理员 需要审核)
    @Override
    public void addClub(Club club) {
        club.setCCreateTime(LocalDateTime.now());
        //未审核为0 , 通过为1 , 未通过为2
        club.setStatus(0);
        clubDao.addClub(club);
    }

    //更新社团信息(团长 =》管理员需要审核)
    @Override
    public void updateClub(Club club) {
        club.setCCreateTime(LocalDateTime.now());
        club.setStatus(0);
        clubDao.updateClub(club);
    }

    //删除社团信息(只有管理员可以删除)
    @Override
    public void deleteClub(Integer cId) {
        clubDao.deleteClub(cId);
    }

    @Override
    public List<Club> getByHeader(String cHeader) {
        List<Club> clubHeaderList = clubDao.getByHeader(cHeader);
        return clubHeaderList;
    }
    //查询社团总数
    @Override
    public Integer getTotal() {
        Integer total = clubDao.getTotal();
        return total;
    }

    @Override
    public void updateStatus(Integer status, Integer cid) {
        clubDao.updateStatus(status , cid);
    }
}
